<?php
namespace app\controllers;

use laiq\base\Controller;
include APP_PATH . '/config/errcode.php';


class BaseController extends Controller
{
    public function __construct($module, $controller, $action) {
        parent::__construct($module, $controller, $action);
        $defaultImage = THEME_PATH . 'img/' . rand(1, 3) . '.jpeg';
        $this->assign('defaultImage', $defaultImage);
    }

    public function error($aError) {
        header('content-type:text/html;charset=uft-8');
        header('location:/empty');
        exit;
    }

    public function output($data, $format='json') {
        if ($format == 'json') {
            header('Content-type: application/json');
        } else {
            header( 'Content-Type:text/html;charset=utf-8 ');
        }

        if (is_array($data)) {
            echo json_encode($data);
        } else {
            echo $data;
        }
        exit;
    }
}